﻿module Sustainalytics.EsgRatings {

    import Common = Sustainalytics.Common;

    export class KeyEsgIssueInfo {

        public rpIndicators: Common.Dictionary<KeyEsgIssueIndicatorDto>;
        public eventIndicators: Common.Dictionary<KeyEsgIssueIndicatorDto>;

        constructor(public keyEsgIssue: KeyEsgIssueDto) {
            var ctx = this;

            ctx.rpIndicators = new Common.Dictionary<KeyEsgIssueIndicatorDto>();
            ctx.eventIndicators = new Common.Dictionary<KeyEsgIssueIndicatorDto>();
        }

        // add indicator
        public addIndicator(indicator: KeyEsgIssueIndicatorDto): void {
            var ctx = this;

            if (indicator.isRpIndicator) {
                ctx.rpIndicators.add(indicator.id, indicator);
            }
            else {
                if (indicator.isEventIndicator) {
                    ctx.eventIndicators.add(indicator.name, indicator);
                }
            }
        }

        // get all indicators associated with current Key ESG Issue
        public getIndicators(): KeyEsgIssueIndicatorDto[] {
            var ctx = this;

            var indicators: KeyEsgIssueIndicatorDto[] = new Array();

            // add RP indicators
            $.each(ctx.rpIndicators.getValues(), function (index, indicator) {
                indicators.push(indicator);
            });

            // add Event indicators
            $.each(ctx.eventIndicators.getValues(), function (index, indicator) {
                indicators.push(indicator);
            });

            return indicators;
        }
    }
}